<template>
  <el-dialog
    :title="!dataForm.resourceId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="房源名称" prop="resourceName">
      <el-input v-model="dataForm.resourceName" placeholder="房源名称"></el-input>
    </el-form-item>
    <el-form-item label="房产类型id" prop="propertyId">
      <el-input v-model="dataForm.propertyId" placeholder="房产类型id"></el-input>
    </el-form-item>
    <el-form-item label="小区名称" prop="resourceQuarters">
      <el-input v-model="dataForm.resourceQuarters" placeholder="小区名称"></el-input>
    </el-form-item>
    <el-form-item label="详细地址" prop="resourceAddress">
      <el-input v-model="dataForm.resourceAddress" placeholder="详细地址"></el-input>
    </el-form-item>
    <el-form-item label="区域id" prop="resourceAid">
      <el-input v-model="dataForm.resourceAid" placeholder="区域id"></el-input>
    </el-form-item>
    <el-form-item label="户型" prop="houseType">
      <el-input v-model="dataForm.houseType" placeholder="户型"></el-input>
    </el-form-item>
    <el-form-item label="朝向" prop="resourceOrientation">
      <el-input v-model="dataForm.resourceOrientation" placeholder="朝向"></el-input>
    </el-form-item>
    <el-form-item label="装修" prop="resourceRenovation">
      <el-input v-model="dataForm.resourceRenovation" placeholder="装修"></el-input>
    </el-form-item>
    <el-form-item label="所在楼层" prop="resourceFloor">
      <el-input v-model="dataForm.resourceFloor" placeholder="所在楼层"></el-input>
    </el-form-item>
    <el-form-item label="总层数" prop="resourceTotalFloor">
      <el-input v-model="dataForm.resourceTotalFloor" placeholder="总层数"></el-input>
    </el-form-item>
    <el-form-item label="面积" prop="resourceArea">
      <el-input v-model="dataForm.resourceArea" placeholder="面积"></el-input>
    </el-form-item>
    <el-form-item label="租金" prop="resourceRent">
      <el-input v-model="dataForm.resourceRent" placeholder="租金"></el-input>
    </el-form-item>
    <el-form-item label="售价" prop="resourcePrice">
      <el-input v-model="dataForm.resourcePrice" placeholder="售价"></el-input>
    </el-form-item>
    <el-form-item label="标签id" prop="resourceLableId">
      <el-input v-model="dataForm.resourceLableId" placeholder="标签id"></el-input>
    </el-form-item>
    <el-form-item label="描述" prop="resourceDescribe">
      <el-input v-model="dataForm.resourceDescribe" placeholder="描述"></el-input>
    </el-form-item>
    <el-form-item label="用户编号" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户编号"></el-input>
    </el-form-item>
    <el-form-item label="用户名(二手房发布人)" prop="userName">
      <el-input v-model="dataForm.userName" placeholder="用户名(二手房发布人)"></el-input>
    </el-form-item>
    <el-form-item label="经纪人编号(指派经纪人)" prop="agentId">
      <el-input v-model="dataForm.agentId" placeholder="经纪人编号(指派经纪人)"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="resourceUpdateDate">
      <el-input v-model="dataForm.resourceUpdateDate" placeholder="修改时间"></el-input>
    </el-form-item>
    <el-form-item label="房源状态0:新房1:二手房2:出租房" prop="resourceStatus">
      <el-input v-model="dataForm.resourceStatus" placeholder="房源状态0:新房1:二手房2:出租房"></el-input>
    </el-form-item>
    <el-form-item label="售出状态0:未售出1:已租赁2:已售出" prop="resourceSoldStatus">
      <el-input v-model="dataForm.resourceSoldStatus" placeholder="售出状态0:未售出1:已租赁2:已售出"></el-input>
    </el-form-item>
    <el-form-item label="房源排序" prop="resourceSort">
      <el-input v-model="dataForm.resourceSort" placeholder="房源排序"></el-input>
    </el-form-item>
    <el-form-item label="审核状态0:未审核1:审核通过2:审核未通过" prop="resourceAuditStatus">
      <el-input v-model="dataForm.resourceAuditStatus" placeholder="审核状态0:未审核1:审核通过2:审核未通过"></el-input>
    </el-form-item>
    <el-form-item label="展示状态0正常展示1不正常隐藏(逻辑删除)" prop="resourceShowStatus">
      <el-input v-model="dataForm.resourceShowStatus" placeholder="展示状态0正常展示1不正常隐藏(逻辑删除)"></el-input>
    </el-form-item>
    <el-form-item label="是否收藏0:已收藏1:未收藏" prop="resourceCollectionStatus">
      <el-input v-model="dataForm.resourceCollectionStatus" placeholder="是否收藏0:已收藏1:未收藏"></el-input>
    </el-form-item>
    <el-form-item label="是否同步es:0未同步 1:已同步" prop="resourceEsStatus">
      <el-input v-model="dataForm.resourceEsStatus" placeholder="是否同步es:0未同步 1:已同步"></el-input>
    </el-form-item>
    <el-form-item label="订单类型1:二手房出租2:有房出租3:我想买个房子4:我想租个房子" prop="resourceOrderId">
      <el-input v-model="dataForm.resourceOrderId" placeholder="订单类型1:二手房出租2:有房出租3:我想买个房子4:我想租个房子"></el-input>
    </el-form-item>
    <el-form-item label="楼盘id" prop="saleId">
      <el-input v-model="dataForm.saleId" placeholder="楼盘id"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          resourceId: 0,
          resourceName: '',
          propertyId: '',
          resourceQuarters: '',
          resourceAddress: '',
          resourceAid: '',
          houseType: '',
          resourceOrientation: '',
          resourceRenovation: '',
          resourceFloor: '',
          resourceTotalFloor: '',
          resourceArea: '',
          resourceRent: '',
          resourcePrice: '',
          resourceLableId: '',
          resourceDescribe: '',
          userId: '',
          userName: '',
          agentId: '',
          resourceUpdateDate: '',
          resourceStatus: '',
          resourceSoldStatus: '',
          resourceSort: '',
          resourceAuditStatus: '',
          resourceShowStatus: '',
          resourceCollectionStatus: '',
          resourceEsStatus: '',
          resourceOrderId: '',
          saleId: ''
        },
        dataRule: {
          resourceName: [
            { required: true, message: '房源名称不能为空', trigger: 'blur' }
          ],
          propertyId: [
            { required: true, message: '房产类型id不能为空', trigger: 'blur' }
          ],
          resourceQuarters: [
            { required: true, message: '小区名称不能为空', trigger: 'blur' }
          ],
          resourceAddress: [
            { required: true, message: '详细地址不能为空', trigger: 'blur' }
          ],
          resourceAid: [
            { required: true, message: '区域id不能为空', trigger: 'blur' }
          ],
          houseType: [
            { required: true, message: '户型不能为空', trigger: 'blur' }
          ],
          resourceOrientation: [
            { required: true, message: '朝向不能为空', trigger: 'blur' }
          ],
          resourceRenovation: [
            { required: true, message: '装修不能为空', trigger: 'blur' }
          ],
          resourceFloor: [
            { required: true, message: '所在楼层不能为空', trigger: 'blur' }
          ],
          resourceTotalFloor: [
            { required: true, message: '总层数不能为空', trigger: 'blur' }
          ],
          resourceArea: [
            { required: true, message: '面积不能为空', trigger: 'blur' }
          ],
          resourceRent: [
            { required: true, message: '租金不能为空', trigger: 'blur' }
          ],
          resourcePrice: [
            { required: true, message: '售价不能为空', trigger: 'blur' }
          ],
          resourceLableId: [
            { required: true, message: '标签id不能为空', trigger: 'blur' }
          ],
          resourceDescribe: [
            { required: true, message: '描述不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '用户编号不能为空', trigger: 'blur' }
          ],
          userName: [
            { required: true, message: '用户名(二手房发布人)不能为空', trigger: 'blur' }
          ],
          agentId: [
            { required: true, message: '经纪人编号(指派经纪人)不能为空', trigger: 'blur' }
          ],
          resourceUpdateDate: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          resourceStatus: [
            { required: true, message: '房源状态0:新房1:二手房2:出租房不能为空', trigger: 'blur' }
          ],
          resourceSoldStatus: [
            { required: true, message: '售出状态0:未售出1:已租赁2:已售出不能为空', trigger: 'blur' }
          ],
          resourceSort: [
            { required: true, message: '房源排序不能为空', trigger: 'blur' }
          ],
          resourceAuditStatus: [
            { required: true, message: '审核状态0:未审核1:审核通过2:审核未通过不能为空', trigger: 'blur' }
          ],
          resourceShowStatus: [
            { required: true, message: '展示状态0正常展示1不正常隐藏(逻辑删除)不能为空', trigger: 'blur' }
          ],
          resourceCollectionStatus: [
            { required: true, message: '是否收藏0:已收藏1:未收藏不能为空', trigger: 'blur' }
          ],
          resourceEsStatus: [
            { required: true, message: '是否同步es:0未同步 1:已同步不能为空', trigger: 'blur' }
          ],
          resourceOrderId: [
            { required: true, message: '订单类型1:二手房出租2:有房出租3:我想买个房子4:我想租个房子不能为空', trigger: 'blur' }
          ],
          saleId: [
            { required: true, message: '楼盘id不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.resourceId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.resourceId) {
            this.$http({
              url: this.$http.adornUrl(`/house/resource/info/${this.dataForm.resourceId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.resourceName = data.resource.resourceName
                this.dataForm.propertyId = data.resource.propertyId
                this.dataForm.resourceQuarters = data.resource.resourceQuarters
                this.dataForm.resourceAddress = data.resource.resourceAddress
                this.dataForm.resourceAid = data.resource.resourceAid
                this.dataForm.houseType = data.resource.houseType
                this.dataForm.resourceOrientation = data.resource.resourceOrientation
                this.dataForm.resourceRenovation = data.resource.resourceRenovation
                this.dataForm.resourceFloor = data.resource.resourceFloor
                this.dataForm.resourceTotalFloor = data.resource.resourceTotalFloor
                this.dataForm.resourceArea = data.resource.resourceArea
                this.dataForm.resourceRent = data.resource.resourceRent
                this.dataForm.resourcePrice = data.resource.resourcePrice
                this.dataForm.resourceLableId = data.resource.resourceLableId
                this.dataForm.resourceDescribe = data.resource.resourceDescribe
                this.dataForm.userId = data.resource.userId
                this.dataForm.userName = data.resource.userName
                this.dataForm.agentId = data.resource.agentId
                this.dataForm.resourceUpdateDate = data.resource.resourceUpdateDate
                this.dataForm.resourceStatus = data.resource.resourceStatus
                this.dataForm.resourceSoldStatus = data.resource.resourceSoldStatus
                this.dataForm.resourceSort = data.resource.resourceSort
                this.dataForm.resourceAuditStatus = data.resource.resourceAuditStatus
                this.dataForm.resourceShowStatus = data.resource.resourceShowStatus
                this.dataForm.resourceCollectionStatus = data.resource.resourceCollectionStatus
                this.dataForm.resourceEsStatus = data.resource.resourceEsStatus
                this.dataForm.resourceOrderId = data.resource.resourceOrderId
                this.dataForm.saleId = data.resource.saleId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/house/resource/${!this.dataForm.resourceId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'resourceId': this.dataForm.resourceId || undefined,
                'resourceName': this.dataForm.resourceName,
                'propertyId': this.dataForm.propertyId,
                'resourceQuarters': this.dataForm.resourceQuarters,
                'resourceAddress': this.dataForm.resourceAddress,
                'resourceAid': this.dataForm.resourceAid,
                'houseType': this.dataForm.houseType,
                'resourceOrientation': this.dataForm.resourceOrientation,
                'resourceRenovation': this.dataForm.resourceRenovation,
                'resourceFloor': this.dataForm.resourceFloor,
                'resourceTotalFloor': this.dataForm.resourceTotalFloor,
                'resourceArea': this.dataForm.resourceArea,
                'resourceRent': this.dataForm.resourceRent,
                'resourcePrice': this.dataForm.resourcePrice,
                'resourceLableId': this.dataForm.resourceLableId,
                'resourceDescribe': this.dataForm.resourceDescribe,
                'userId': this.dataForm.userId,
                'userName': this.dataForm.userName,
                'agentId': this.dataForm.agentId,
                'resourceUpdateDate': this.dataForm.resourceUpdateDate,
                'resourceStatus': this.dataForm.resourceStatus,
                'resourceSoldStatus': this.dataForm.resourceSoldStatus,
                'resourceSort': this.dataForm.resourceSort,
                'resourceAuditStatus': this.dataForm.resourceAuditStatus,
                'resourceShowStatus': this.dataForm.resourceShowStatus,
                'resourceCollectionStatus': this.dataForm.resourceCollectionStatus,
                'resourceEsStatus': this.dataForm.resourceEsStatus,
                'resourceOrderId': this.dataForm.resourceOrderId,
                'saleId': this.dataForm.saleId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
